package com.mall.utils;

import org.apache.commons.mail.HtmlEmail;

/**
 * java邮件发送，  QQ邮箱发送
 */
public class EmailUtils {

    private static final String USERNAME = "1738180253@qq.com";
    private static final String PASSWORD = "lvcptqtrxtpicbaj";

    public static boolean  sendEmail(String []emails,String msg,String title){
        try{
            HtmlEmail email = new HtmlEmail();
            //基本设置
            email.setSSL(true);
            email.setDebug(true);
            //设置主邮箱为QQ邮箱
            email.setHostName("SMTP.qq.com");
            email.setSmtpPort(587);

            //设置发送的邮箱 PASSWORD不是QQ,QQ邮箱密码
            email.setAuthentication(USERNAME,PASSWORD);
            email.setFrom(USERNAME);

            email.addTo(emails);
            email.setMsg(msg);
            email.setSubject(title);
            //执行发送
            email.send();
            return true;
        }catch (Exception e){
            e.printStackTrace();
        }
        return false;
    }

    public static void main(String[] args) {
        String emails [] = {"1738180253@qq.com"};
        String msg = "测试邮寄发送!";
        String title = "某某网站的密码找回";
        boolean b = sendEmail(emails, msg, title);
        System.out.println("邮件发送"+(b?"成功":"失败"));
    }

}
